package dk.netl.dashboard.widgets.alivewidget;

import javafx.scene.shape.Rectangle;
import javafx.scene.Group;
import javafx.scene.paint.Color;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import dk.netl.dashboard.widgets.AbstractDashboardWidget;

public class AliveWidget extends Group, AbstractDashboardWidget {

    public var x: Number;
    public var y: Number;
    public var width: Number;
    public var height: Number;
    var orgX: Number;
    var orgY: Number;
    var orgWidth: Number;
    var orgHeight: Number;
    var allOk: Boolean;

    var aliveRows = [];

    def aiteAliveRow: AliveRow = AliveRow {
                serverInfo: new ServerInfoImpl(0, "Ejendom", "http://cc-t-d101-c01-s02.cr.root4.net:7501/netl-server");
            }
    def aite2AliveRow: AliveRow = AliveRow {
                serverInfo: new ServerInfoImpl(1, "Bilbog", "http://cc-t-d134-c01-s02.cr.root4.net:7501/bilbog-server");
            }
    def update: Timeline = Timeline {
                repeatCount: Timeline.INDEFINITE
                keyFrames: [
                    KeyFrame {
                        time: 10s
                        action: function () {
                            aiteAliveRow.updateState();
                            aite2AliveRow.updateState();
                            
                            allOk = aiteAliveRow.isAlive and aite2AliveRow.isAlive;
                        }
                    }
                ]
            };

    init {

        orgX = x;
        orgY = y;
        orgWidth = width;
        orgHeight = height;
        update.play();

        content = [
                    Rectangle {
                        arcHeight: 30
                        arcWidth: 30
                        opacity: 0.5
                        fill: Color.web("#005284", 1.0)
                        x: bind x
                        y: bind y
                        width: bind width
                        height: bind height
                    }, aiteAliveRow
                    , aite2AliveRow
                ]
    }

}
